import os
import scipy.io as scio
import numpy as np
import tqdm
import csv


# dir need end by /
originDataSetDir = "./DataSetProcess/sample2017/validation/"
outcomeDataSetDir = "./DataSetProcess/Myvalidation/"

if not os.path.exists(originDataSetDir):
    print("The orginal dataset directory is not exist!")
    exit(1)
    
if os.path.exists(outcomeDataSetDir):
    print("The outcome dataset directory is allready exist!")
    exit(1)
os.makedirs(outcomeDataSetDir)

with open(originDataSetDir+"REFERENCE.csv") as csvfile:
    csv_reader = csv.reader(csvfile)  # 使用csv.reader读取csvfile中的文件
    for i in csv_reader:
        filename = i[0]
        print("Processing {}".format(filename))
        data = scio.loadmat(originDataSetDir+filename+".mat")["val"][0]
        np.save(outcomeDataSetDir+filename, data)
